﻿@{
    ViewBag.Title = "Form"; 
    Layout = "~/Views/Shared/_Form.cshtml";
}
<script>
     layui.use(['jquery', 'form', 'laydate', 'common','optimizeSelectOption', 'upload', 'util'], function () {
        var form = layui.form,
            $ = layui.$,
            common = layui.common,
            laydate = layui.laydate,
             upload = layui.upload,
            util = layui.util;
        var keyValue = $.request("keyValue");
             $('#F_UserId').val($.request("F_UserId"));
             $('#F_RealName').val(decodeURI($.request("F_RealName")));
             $('#F_UserNum').val(decodeURI($.request("F_UserNum")));
        //权限字段
        common.authorizeFields('adminform');
        //此处需修改
        //类型为时间时
        laydate.render({
             elem: '#F_StartDate'
            , btns: ['clear', 'now']
            , trigger: 'click',
            format: 'yyyy-MM-dd',
        });
           laydate.render({
               elem: '#F_EndDate'
             , btns: ['clear', 'now']
             , trigger: 'click',
             format: 'yyyy-MM-dd',
         });
            laydate.render({
               elem: '#F_StopDate'
             , btns: ['clear', 'now']
             , trigger: 'click',
             format: 'yyyy-MM-dd',
         });
           //普通图片上传
             var uploadInst = upload.render({
                 elem: '#upload'
                 , url: '/FileManage/Uploadfile/Upload' //改成您自己的上传接口
                 , size: 1024
                 , accept: 'file'
                  , data: { filetype: 1, fileby: '合同附件',imgurl:'contract' }
                 , choose: function (obj) {
                     //预读本地文件示例，不支持ie8
                     obj.preview(function (index, file, result) {
                          $('#F_Appendix').attr('src', result); //图片链接（base64）
                     });
                 }
                 , done: function (res) {
                     //如果上传失败
                     if (res.code > 0) {
                         //失败状态，并实现重传
                         // var demoText = $('#demoText');
                         // demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                         // demoText.find('.demo-reload').on('click', function () {
                         //     uploadInst.upload();
                         // });
                         common.modalMsg(res.msg, "warning");
                         return false;
                     }
                      $('#F_Appendix').val(res.data[0].src);
                 }
                 , error: function () {
                     //演示失败状态，并实现重传
                     // var demoText = $('#demoText');
                     // demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                     // demoText.find('.demo-reload').on('click', function () {
                     //     uploadInst.upload();
                     // });
                 }
             });
        $(function () {
            initControl();
            if (!!keyValue) {
                 common.ajax({
                   url: '/ContractManagement/ContractMaintain/GetFormJson',
                   dataType: 'json',
                   data: { keyValue: keyValue },
                   async: false,
                   success: function (data) {
                       common.val('adminform', data);
                           $("#F_EndDate").val(util.toDateString(data.F_EndDate, 'yyyy-MM-dd'));
                           $("#F_StartDate").val(util.toDateString(data.F_StartDate, 'yyyy-MM-dd'));
                           $("#F_StopDate").val(util.toDateString(data.F_StopDate, 'yyyy-MM-dd'));
                           $('#F_Appendix').attr('src', data.F_ImgUrl); //图片链接
                    }
               });
           }
           form.render();
       });
       wcLoading.close();

       function initControl() {
           //此处需修改
           //绑定数据源
           //类型为下拉框时
               $("#F_FullName").bindSelect({
                  url: "/SystemManage/ItemsData/GetSelectJson?enCode=ContractType",
                 id: "id",
                 text: "text"
             });
       }

       //监听提交
       form.on('submit(saveBtn)', function (data) {
           var postData = data.field;
                if (!postData["F_EnabledMark"]) postData["F_EnabledMark"] = false;
           common.submitForm({
               url: '/ContractManagement/ContractMaintain/SubmitForm?keyValue=' + keyValue,
               param: postData,
               success: function () {
                   common.parentreload('data-search-btn');
               }
           })
           return false;
       });
   });
     function search(fileds) {
         layui.use(['jquery', 'form', 'common'], function () {
             var form = layui.form,
                 $ = layui.$,
                 common = layui.common;
             //不同弹窗
             if (fileds == '人员') {
                 common.modalOpen({
                     title: "选择角色",
                        url: "/SystemOrganize/User/AddForm?name=" + "F_RealName" + "&value=" + "F_RealNameId" + "&ids=" + $('#F_RealNameId').val(),
                     width: "650px",
                     height: "600px",
                 });
             }
             
             else {
                 return false;
             }
         });
     }
</script>

<body>
    <div class="layuimini-container">
        <div class="layuimini-main">
            <div class="layui-form layuimini-form" lay-filter="adminform">
                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label required">状态</label>
                    <div class="layui-input-block">
                        <input id="F_EnabledMark" name="F_EnabledMark" type="checkbox" lay-skin="switch" lay-text="正常|关闭" checked value="true">
                    </div>
                </div>
                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label required">工号</label>
                    <div class="layui-input-block">
                        <input type="text" id="F_UserNum" name="F_UserNum" autocomplete="off" lay-verify="required" placeholder="请输入" class="layui-input" onclick="search('人员')">
                        <input id="F_UserId" name="F_UserId" type="text" hidden />
                    </div>
                </div>
                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label required">姓名</label>
                    <div class="layui-input-block">


                        <input id="F_RealName" name="F_RealName" type="text" lay-verify="required" maxlength="50" autocomplete="off" class="layui-input" />
                    </div>
                </div>
                <div class="layui-form-item layui-hide">
                   <label class="layui-form-label required">合同编号</label>
                   <div class="layui-input-block">
                        <input type="text" id="F_EnCode" name="F_EnCode" autocomplete="off" lay-verify="required" placeholder="请输入" class="layui-input">
                   </div>
               </div>
                <div class="layui-form-item layui-hide">
                   <label class="layui-form-label required">合同名称</label>
                   <div class="layui-input-block">
                        <select id="F_FullName" name="F_FullName" lay-verify="required" lay-search="">
                        </select>
                   </div>
               </div>
                
                <div class="layui-form-item layui-hide">
                   <label class="layui-form-label required">开始日期</label>
                   <div class="layui-input-block">
                        <input type="text" id="F_StartDate" name="F_StartDate" autocomplete="off" lay-verify="required" placeholder="请输入" class="layui-input">
                   </div>
               </div>
                <div class="layui-form-item layui-hide">
                   <label class="layui-form-label required">结束日期</label>
                   <div class="layui-input-block">
                        <input type="text" id="F_EndDate" name="F_EndDate" autocomplete="off" lay-verify="required" placeholder="请输入" class="layui-input">
                   </div>
               </div>
                <div class="layui-form-item layui-hide">
                   <label class="layui-form-label ">终止日期</label>
                   <div class="layui-input-block">
                        <input type="text" id="F_StopDate" name="F_StopDate" autocomplete="off" lay-verify="required" placeholder="请输入" class="layui-input" readonly>
                   </div>
               </div>
                <div class="layui-form-item layui-hide">
                   <label class="layui-form-label ">附件</label>
                   <div class="layui-input-block">
                        <input type="text" id="F_Appendix" name="F_Appendix" autocomplete="off"  placeholder="请输入" class="layui-input">
                        <button type="button" class="layui-btn" id="upload" style=" margin-top: 10px">上传图片</button>
                    </div>
               </div>
             
              
              
                <div class="layui-form-item layui-hide">
                   <label class="layui-form-label">备注</label>
                   <div class="layui-input-block">
                        <input type="text" id="F_Description" name="F_Description" autocomplete="off"  placeholder="请输入" class="layui-input">
                   </div>
               </div>
               
                <div class="layui-form-item layui-hide">
                    <button class="layui-btn site-demo-active" lay-submit id="submit" lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</body>

